#include "../entities.hpp"
#include "../macros.hpp"

using lms::entities::Customer;
using lms::entities::User;
using lms::entities::OrderDetail;
using lms::entities::Order;

int Order::orderNumber=0;

Order::Order(){

    orderDetails = new LinkedList< OrderDetail >();    
    customer = null;
    ++orderNumber;
}

Order::Order(Customer* customer, OrderDetail* orderDetail){
    this->customer = customer;
    
    addOrderDetail( orderDetail );
    ++orderNumber;
}


void Order::addOrderDetail(OrderDetail* orderDetail){
    
    if( orderDetails == null )
        return;
    orderDetails->add( orderDetail );
}

void Order::removeOrderDetail(int index)
{
    if(orderDetails !=null )
        orderDetails->remove(index);
}

double Order::getTotalCost(){

    if( orderDetails == null )
        return 0.0;
    
    double total = 0.0;
    
    Node< OrderDetail >* first = orderDetails->getFirst();
       
    while( first != null )
    {
        OrderDetail* retrievedDetail = first->getData();
        total += ( retrievedDetail->getBookAmountPerUnit() ) * (retrievedDetail->getPurchasedBook())->getPrice() ;
        first = first->getNext();
    }
    return total;
}


void Order::setOrderDetails(LinkedList<OrderDetail>* orderDetails) {
    this->orderDetails = orderDetails;
}

LinkedList<OrderDetail>* Order::getOrderDetails() const {
    return orderDetails;
}

void Order::setCustomer(Customer* customer) {
    this->customer = customer;
}

Customer* Order::getCustomer() const {
    return customer;
}





